/*
 *登录页面文件
 */
'use strict';
import React, { Component } from 'react';
import { Link,browserHistory } from 'react-router';
import { connect } from 'react-redux';
import { formatTime } from '@app/constants/CommonFn.jsx';
import { Form, Icon, Input, Button, Checkbox, Alert } from 'antd';
import {adminUser} from '@app/constants/DataSource.jsx';
const FormItem = Form.Item;

class login extends Component {
  constructor(props) {
    super(props);
    this.state = {
    	show:'none',
    };
  }

  componentDidMount(){
  }

	handleSubmit = (e) => {
    e.preventDefault();
    this.props.form.validateFields((err, values) => {
      if (!err) {
      	if(values.userName === 'admin' && values.password === '123456'){
      		adminUser.login = true;
      		this.setState({show:'none'});
					browserHistory.push('/Analysis');
      	}else{
      		this.setState({show:''});
      	}
      }
    });
  }

  render() {  
		const { getFieldDecorator } = this.props.form;
    return (
    	<div className = 'loginBG'>
    	<img src='../../static/img/loginBG1.png'/>
	    	<div className="login">
		      <Form onSubmit={this.handleSubmit} style = {{width:300}}>
		      	<h1 className = 'title'>环境监测登录</h1>
		      	<Alert message="账户或密码错误(admin/123456)" type="error" showIcon style = {{display:this.state.show}}/>
		        <FormItem>
		          {getFieldDecorator('userName', {
		            rules: [{ required: true, message: '请输入用户名(admin)!' }],
		          })(
		            <Input prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />} placeholder="请输入用户名(admin)" />
		          )}
		        </FormItem>
		        <FormItem>
		          {getFieldDecorator('password', {
		            rules: [{ required: true, message: '请输入密码(123456)!' }],
		          })(
		            <Input prefix={<Icon type="lock" style={{ color: 'rgba(0,0,0,.25)' }} />} type="password" placeholder="请输入密码(123456)" />
		          )}
		        </FormItem>
		        <FormItem>
		          {getFieldDecorator('remember', {
		            valuePropName: 'checked',
		            initialValue: true,
		          })(
		            <Checkbox>自动登录</Checkbox>
		          )}
		          <Button type="primary" htmlType="submit" className="login-form-button" style = {{float:'right'}}>
		            登录
		          </Button>
		        </FormItem>
		      </Form>
		     </div>
	     </div>
    );
  }
}

const Login = Form.create()(login);

function mapStateToProps(state) {
  return {
   
  }
}
export default connect(
  mapStateToProps, {
    
  }
)(Login)
